function getContext() {
    var curPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var index = curPath.indexOf(pathName);
    var localhost = curPath.substring(0, index);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    return (localhost + projectName);
}

function display(title,url,width,height){
    layer.open({
        type: 2,
        title: title,
        shadeClose: true,
        shade: 0.8,
        area: [width, height],
        content: url
    });
}

// 验证实数
function validateRealNum(val){
    var patten = /^-?\d+\.?\d*$/;
    return patten.test(val);
}

// 验证整数
function validateNum(val){
    var patten = /^-?\d+$/;
    return patten.test(val);
}

// 通用删除
function del(url,id){
    layer.confirm("确认删除ID为 [" + id + "] 的数据吗？",function(){
        layer.close(layer.index);
        $.ajax({
            type : "DELETE",
            url : getContext() + url + id,
            dataType : "json",
            beforeSend : function(xhr){},
            success : function(data){
                var icon = 100 === data.code? 6:2;
                layer.msg(data.msg,{icon: icon,time:1500},function(){
                    if(100 === data.code){
                        $('#table').bootstrapTable('refresh', null);
                    }
                });
            },
            error : function(xhr, textStatus, errorThrown){
                console.log(xhr.status);
                console.log(xhr.statusText);
                console.log(xhr.responseText);
            }
        });
    });
}

